from selenium import webdriver
import time
from selenium.webdriver import ActionChains

# 定义浏览器对象
browser = webdriver.Chrome('D:\python\爬虫\chromedriver.exe')

# 打开网址
browser.get('http://localhost:8080/login')

time.sleep(1)

# 填入用户名
browser.find_elements_by_tag_name('input')[1].send_keys('刘川')
time.sleep(1)

# 填入密码
browser.find_elements_by_tag_name('input')[2].send_keys('123')
time.sleep(1)

# 定义拖动对象
button = browser.find_element_by_xpath(
    '//*[@id="app"]/div/section/center/div/div[3]')

# 定义动作对象
action = ActionChains(browser)

# 定义动作类型
action.click_and_hold(button).perform()

# 释放圆球
action.reset_actions()

# 拖动距离
action.move_by_offset(212, 0).perform()

time.sleep(1)

# 点击登录按钮
browser.find_element_by_class_name('h-btn').click()

time.sleep(1)

# 关闭浏览器
# browser.close()
